$(document).ready(function() {
			var userId = $.cookie('userId');
			$("#form_msg").find("input").attr('disabled',true);
			$.ajax({
                type: "post",
                async: false,
                url: "/eshop-project/user/getUserById?UserID=" + userId,
                success: function (data) {
                	$("input[name='userId']").val(data.userId);
                	$("input[name='password']").val(data.password);
					$("input[name='userName']").val(data.userName);
					$("input[name='brith']").val(data.brith);
					$("input[name='email']").val(data.email);
					$("input[name='userRealName']").val(data.userRealName);
					if (data.sex == 'M') {
						$("input[name='sex'][value='M']").attr("checked",true);
					} else {
						$("input[name='sex'][value='F']").attr("checked",true);
					}
					
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.readyState);
                    alert(textStatus);
                },
            });
            $("#updateMsg").click(function(){
            	if ($("input[name='userName']").is(':disabled')) {
            		$("#form_msg").find("input").attr('disabled',false);
            	} else {
                	var params = $("#form_msg").find("input").serializeArray();
                	var data = jQuery.param(params);
                	console.log(data);
                	$.ajax({
                        type: "post",
                        async: false,
                        url: "/eshop-project/user/updateUser?" + data,
                        success: function (data) {
                        	console.log(data);
        					alert("修改您的个人信息成功！");
        					window.location.reload();
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest.status);
                            alert(XMLHttpRequest.readyState);
                            alert(textStatus);
                        },
                    });
            	}
            });
            $("#btn-updatePwd").click(function(){
            	var password = $("input[name='newPassword']").val();
            	var userId = $("input[name='userId']").val();
            	$.ajax({
                    type: "post",
                    async: false,
                    url: "/eshop-project/user/updatePwd?newPassword=" + password + "&userId=" + userId,
                    success: function (data) {
                    	console.log(data);
    					alert("修改您的账户密码成功！");
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    },
                });
            });
		});